﻿using UnityEngine;
using ProtoBuf.Message;

namespace UI
{
    public class CopyBenefit : UIActivityTemplate
    {
        public UILabel title;
        public UILabel content;
        public UISprite goBtn;
        public UISprite word;
        const string copy = "copyDouble";
        const string dailyCopy = "dailyCopyDouble";
        const string aincrad = "aincradDouble";
        string copyId;
        public ActivityType type;
        public override void OnCoverPageRemove()
        {
            base.OnCoverPageRemove();
        }
        protected override void PrepareData()
        {
            type= activityType;
            if (type == ActivityType.CopyBenefits)
            {
                title.text = "[fdbec5]"+TableTextBlo.GetText("activity_Benefits_tab")+"[-]";
            }
            else if(type  == ActivityType.RechangeDouble)
            {
                title.text = TableTextBlo.GetText("activity_warrior_weight_improve_title");
            }
            else
            {
                title.text = TableTextBlo.GetText("activity_warrior_weight_improve_title");
            }

        }

        public override void Show()
        {
            base.Show();
            CSCopyBoonInfo msg = new CSCopyBoonInfo();
            msg.activityId = activityId;
            NetAPI.SendHttp(OpDefine.CSCopyBoonInfo, msg, MsgCallback);
        }
        void MsgCallback(NetWork.Packets.Packet packet, bool success)
        {
            if (success)
            {
                SCCopyBoonInfo msg = packet.kBody as SCCopyBoonInfo;
                content.text = msg.information;
                copyId = msg.activityId;

                if (content.height < 130 )
                    content.GetComponent<UIDragScrollView>().enabled = false;
                else
                    content.GetComponent<UIDragScrollView>().enabled = true;

                if(msg.activityId.Contains(";"))
                {
                    goBtn.enabled = false;
                    word.enabled = false;
                }
                else
                {
                    goBtn.enabled = true;
                    word.enabled = true;
                }
            }
        }

        public void OnBtnGoClick()
        {
            //充值双倍
            if (type == ActivityType.RechangeDouble)
            {
                PageManager.Instance.OpenPage("ChargePage", "");
                return;
            }

            //您当前位于监狱中，不能进行该操作
            if (StaticData.isPlayerNeedJail)
            {
                BoxManager.CreatePopupTextBox(TableTextBlo.GetText("prison_you_cannot_do"));
                return;
            }

            if (copyId == "townSideCollectRateActivity" || copyId == "townSideBossRateActivity" || copyId == "piLaoHalfDiscountActivity")
            {
                PageManager.Instance.OpenPage("WorldMapPage", "");
                return;
            }
            if (StaticData.playerData.IsHeroFull())
            {
                 BoxManager.ShowHeroFull();
                 return;
            }
            if (StaticData.playerData.IsEquipFull())
            {
                 BoxManager.ShowEquipFull();
                 return;
            }

            if (type == ActivityType.CopyBenefits)
            {
                switch (copyId)
                {
                    case copy://主线副本
                    case copy + "Festival":
                        //UICopy
                        PageManager.Instance.OpenPage("UICopy", "");
                        break;
                    case dailyCopy://日常副本
                    case dailyCopy + "Festival":
                    case "dailyCopyTimesActivity":
                        PageManager.Instance.OpenPage("ActivityCopyPage", "type=0");
                        break;
                    case aincrad://试炼副本
                    case aincrad + "Festival":
                        PageManager.Instance.OpenPage("RushPage", "");
                        break;
                    case "expeditionRateActivity": //佣兵-远征
                        PageManager.Instance.OpenPage("MercenaryTaskPage", "tab=0");
                        break;
                    case "singleScoreRateActivity":
                    case "scoreRankRateActivity"://佣兵 -悬赏
                        PageManager.Instance.OpenPage("MercenaryTaskPage", "tab=1");
                        break;
                    case "popularityRateActivity": //PVP竞技场
                        PageManager.Instance.OpenPage("ArenaPage", "");
                        break;
                }
            }
            else if (type == ActivityType.WarriorWeightImprove)
            {
                PageManager.Instance.OpenPage("ShopPage", "");
            }
            else
            {
                Debug.LogError("该类型活动不存在");
            }
        }
    }
}



